package biz

import (
	"context"

	"github.com/go-kratos/kratos/v2/log"
)

// Greeter is a Greeter model.
type Greeter struct {
	Hello string
}

// GreeterRepo is a Greater repo.
type GreeterRepo interface {
	Save(context.Context, *Greeter) (*Greeter, error)
	Update(context.Context, *Greeter) (*Greeter, error)
	FindByID(context.Context, int64) (*Greeter, error)
	ListByHello(context.Context, string) ([]*Greeter, error)
	ListAll(context.Context) ([]*Greeter, error)
}

// GreeterBiz is a Greeter usecase.
type GreeterBiz struct {
	repo    GreeterRepo
	log     *log.Helper
	baseBiz *BaseBiz
}

func NewGreeterBiz(repo GreeterRepo, logger log.Logger, baseBiz *BaseBiz) *GreeterBiz {
	return &GreeterBiz{
		repo:    repo,
		log:     log.NewHelper(logger),
		baseBiz: baseBiz,
	}
}

// CreateGreeter creates a Greeter, and returns the new Greeter.
func (uc *GreeterBiz) CreateGreeter(ctx context.Context, g *Greeter) (*Greeter, error) {
	uc.log.WithContext(ctx).Infof("CreateGreeter: %v", g.Hello)
	return uc.repo.Save(ctx, g)
}
